package cn.stylefeng.guns.modular.rms.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.rms.entity.Company;
import cn.stylefeng.guns.modular.rms.model.params.CompanyParam;
import cn.stylefeng.guns.modular.rms.model.result.CompanyResult;
import cn.stylefeng.guns.modular.rms.service.CompanyService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 公司信息表控制器
 *
 * @author yzb
 * @Date 2021-03-23 12:33:36
 */
@Controller
@RequestMapping("/company")
public class CompanyController extends BaseController {

    private String PREFIX = "/rms/company";

    @Autowired
    private CompanyService companyService;

    /**
     * 跳转到主页面
     *
     * @author yzb
     * @Date 2021-03-23
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/company.html";
    }


    /**
     * 跳转到公司认证
     *
     * @author yzb
     * @Date 2021-03-23
     */
    @RequestMapping("/auth")
    public String auth() {
        return PREFIX + "/company_auth.html";
    }

    /**
     * 新增页面
     *
     * @author yzb
     * @Date 2021-03-23
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/company_add.html";
    }

    /**
     * 编辑页面
     *
     * @author yzb
     * @Date 2021-03-23
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/company_edit.html";
    }

    /**
     * 新增接口
     *
     * @author yzb
     * @Date 2021-03-23
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(CompanyParam companyParam) {
        this.companyService.add(companyParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author yzb
     * @Date 2021-03-23
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(CompanyParam companyParam) {
        this.companyService.update(companyParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author yzb
     * @Date 2021-03-23
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(CompanyParam companyParam) {
        this.companyService.delete(companyParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口+
     *
     * @author yzb
     * @Date 2021-03-23
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(CompanyParam companyParam) {
        CompanyResult detail = this.companyService.findBySpec(companyParam);
        detail.setWorkTime(detail.getStartTime()+"-"+detail.getEndTime());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author yzb
     * @Date 2021-03-23
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(CompanyParam companyParam) {
        return this.companyService.findPageBySpec(companyParam);
    }

    /**
     * 查询列表
     *
     * @author yzb
     * @Date 2021-03-23
     */
    @ResponseBody
    @RequestMapping("/authList")
    public LayuiPageInfo authList(CompanyParam companyParam) {
        companyParam.setStatus(-1);//查询提交过认证的
        return this.companyService.findPageBySpec(companyParam);
    }

    /**
     * 公司认证审核
     *
     * @author yzb
     * @Date 2021-03-23
     */
    @RequestMapping("/companyAuth")
    @ResponseBody
    public ResponseData companyAuth(CompanyParam companyParam) {
        this.companyService.auth(companyParam);
        return ResponseData.success();
    }

}


